package com.hanson.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hanson.demo.actors.Message;
import com.hanson.demo.queue.TbQueueProducer;

import lombok.extern.slf4j.Slf4j;

/**
 * kafka生产者【实际上就是一个Controller，用来进行消息生产】
 * 
 * @author hanson
 *
 */
@Slf4j
@RestController
public class KafkaProducerController {
	private final static String TOPIC_NAME = "hanson"; // topic的名称
	private final static String TOPIC_NAME_lai = "lai.aa.hua";
	@Autowired
	private TbQueueProducer queueProducer;

	@RequestMapping("/send")
	public void send() {
		log.info("send:{}",TOPIC_NAME);
		for (int i = 0; i < 10; i++) {
			Message message = new Message(i+"","hanson");
			// 发送功能就一行代码~
			queueProducer.send(TOPIC_NAME, message,null);
		}
	}
	
	@RequestMapping("/sendGroup")
	public void sendGroup() {
		log.info("send:{}",TOPIC_NAME_lai);
		// 发送功能就一行代码~
		for (int i = 0; i < 10; i++) {
			Message message = new Message(i+"","hanson");
			// 发送功能就一行代码~
			queueProducer.send(TOPIC_NAME_lai, message,null);
		}
	}
}
